package com.warehouse_management.purchase.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.warehouse_management.config.PageModel;
import com.warehouse_management.purchase.dao.ProductTypeDao;
import com.warehouse_management.purchase.model.Brand;
import com.warehouse_management.purchase.model.ProductCondition;
import com.warehouse_management.purchase.model.Type;
import com.warehouse_management.purchase.model.TypeCondition;
import com.warehouse_management.purchase.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PACKAGE_NAME: com.warehouse_management.purchase.service.impl
 * @NAME: ProductTypeServiceImpl
 * @USER: ZhouYongCheng
 * @DATE: 2022/10/3
 * @TIME: 2:55
 * @Description: 商品类型管理服务层实现类
 */
@Service
public class ProductTypeServiceImpl extends ServiceImpl<ProductTypeDao, TypeCondition> implements ProductTypeService {

    @Autowired
    private ProductTypeDao productTypeDao;

    @Override
    public PageModel<TypeCondition> PageTypePosition(TypeCondition type, PageModel<TypeCondition> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()==0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()==0?1: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<TypeCondition> typeConditions = productTypeDao.queryTypeList();
        PageInfo<TypeCondition> pageInfo = new PageInfo<>(typeConditions);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageModel.getTotalPage());
        pageModel.setData(pageInfo.getList());

        return pageModel;
    }

    @Override
    public PageModel<TypeCondition> queryTypeListByCondition(TypeCondition type, PageModel<TypeCondition> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()==0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()==0?1: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<TypeCondition> typeConditionList = productTypeDao.queryTypeListByCondition(type);
        PageInfo<TypeCondition> pageInfo = new PageInfo<>(typeConditionList);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageModel.getTotalPage());
        pageModel.setData(pageInfo.getList());
        return pageModel;
    }

    @Override
    public int addType(TypeCondition type) {
        return productTypeDao.addType(type);
    }

    @Override
    public int updateType(TypeCondition type) {
        return productTypeDao.updateType(type);
    }

    @Override
    public int updateTypeStatus(TypeCondition type) {
        return productTypeDao.updateTypeStatus(type);
    }

    @Override
    public List<Type> queryType() {
        return productTypeDao.queryType();
    }

    @Override
    public List<Brand> queryBrand() {
        return productTypeDao.queryBrand();
    }
}
